package hanjia;

/**
 * Description:
 * Author:    Dane
 * CreateTime:2025/2/12-下午3:01
 * Since  :   1.0
 * Version:   1.0
 */
public class LeetCode235 {

    public TreeNode lowestCommonAncestor(TreeNode root, TreeNode p, TreeNode q) {
        while (root != null) {
            if (root.val > p.val && root.val > q.val) {
                root = root.left;
            } else if (root.val < p.val && root.val < q.val) {
                root = root.right;

            } else {
                return root;
            }
        }
        return root;


    }
}
